<?php
/**
 * @file $HeadURL: keyword.php $
 * @author $Author: Jim.Chou (zhouzhe@haibao.com) $
 * @date $Date: 2015-3-28 16:02:34 $
 * @brief 
 */
namespace haibao\cms\business;
use haibao\cms\business\BusinessException;
use \haibao\cms\data\Keyword as KeywordData; 
use \haibao\cms\business\Tag as TagBusiness;

class Keyword extends \haibao\cms\business\Base{
	
	public static function addKeyword($model){
		self::checkOperation(self::FUNC_CODE_KEYWORD_ADD);
		$keywordData = new KeywordData();
		$keywordData->addKeyword($model);
		self::saveOperateHistory(self::FUNC_CODE_KEYWORD_ADD, $model);
	}
	
	public static function addKeywords($models){
		self::checkOperation(self::FUNC_CODE_KEYWORD_ADD);
		
		if(!$models){
			throw new BusinessException('当前关键词已存在或无输入');
		}
		foreach($models as $model){
			$keywordData = new KeywordData();
			$keywordData->addKeywordOne($model);
		}
		
		self::saveOperateHistory(self::FUNC_CODE_KEYWORD_ADD, $models);
	}
	
	public static function hasExistKeywordInTagEnable($keywordArr){
		$keyword = array();
		if($keywordArr){
			foreach($keywordArr as $keywordName){
				if(TagBusiness::getTagByTagName(strtolower($keywordName))){
					array_push($keyword,$keywordName);
				}
			}
		}
		return $keyword;
	}
	
	public static function checkNameUnique($keywordModelArr){
		$keywordData = new KeywordData();
		return $keywordData->checkNameUnique($keywordModelArr);
	}
	
	public static function getModelById($keywordId){
		if(!$keywordId){
			return NULL;
		}
		$keywordData = new KeywordData();
		return $keywordData->getModelById($keywordId);
	}
	public static function getKeywordList($keywordFilter){
		
		$keywordData = new KeywordData();
		return $keywordData->getKeywordList($keywordFilter);
	}
	
	public static function delKeyword($id){
		self::checkOperation(self::FUNC_CODE_KEYWORD_DEL);
		if (!$id){
			throw new BusinessException('关键词Id不能为空',self::FUNC_CODE_KEYWORD_LIST);
		}
		$keywordData = new KeywordData();
		$keywordData->delKeyword($id);
		
		self::saveOperateHistory(self::FUNC_CODE_KEYWORD_DEL, array($id));
	}
	public static function getKeywrodsByIds($ids){
		if(!$ids){
			return array();
		}else{
			$keywordData = new KeywordData();
			return $keywordData->getKeywordsByIds($ids);
		}	
	}
}
